package edu.yngsxy.communityservice.core.ai.service;

import cn.hutool.ai.AIServiceFactory;
import cn.hutool.ai.ModelName;
import cn.hutool.ai.core.AIConfigBuilder;
import cn.hutool.ai.core.AIService;
import cn.hutool.ai.model.doubao.DoubaoService;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.yngsxy.communityservice.core.util.WkRedisService;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * AI服务
 */
@Service
public class WkDoubaoService extends WkAIService  {
    @Value("${ai.doubao.apikey}")
    private String apikey;
    @Value("${ai.doubao.model}")
    private String model;
    public DoubaoService doubaoService;;// doubao服务
    @PostConstruct
    public void init() {// 初始化doubao服务
        doubaoService = AIServiceFactory.getAIService(new AIConfigBuilder(ModelName.DOUBAO.getValue()).setApiKey(apikey).setModel(model).build(), DoubaoService.class);
    }

    public WkDoubaoService(StringRedisTemplate redis, ObjectMapper mapper, WkRedisService wkRedisService) {//构造函数
        super(redis, mapper, wkRedisService);
    }

    @Override
    protected AIService getAiService() {// 获取deepseek服务
        return doubaoService;
    }

    public String chat(String msg) {// 聊天接口
        return super.chat(msg, ModelName.DOUBAO.getValue());
    }

    public Map<String, Object> chat(MultiTurnChatMessage msg) {// 多轮聊天接口
        return super.chat(msg, ModelName.DOUBAO.getValue());
    }

}

